/**
* 基础菜单 基础管理 个人中心
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>基础管理</el-breadcrumb-item>
      <el-breadcrumb-item>个人中心</el-breadcrumb-item>
    </el-breadcrumb>
    <!--表单-->
    <el-form label-width="120px" :model="editForm" :rules="rules" ref="editForm" style="margin: 40px 0px 0px 200px;">
      <el-form-item label="用户名" prop="username">
        <el-input size="small" v-model="editForm.username" auto-complete="off" style="width: 30%;" readonly="readonly"></el-input>
      </el-form-item>
      <el-form-item label="我的角色" prop="role_name">
        <el-input size="small" v-model="editForm.role_name" auto-complete="off" style="width: 30%;" readonly="readonly"></el-input>
      </el-form-item>
      <el-form-item label="我的权限" prop="left_menu_id">
        <el-select placeholder="我的权限" v-model="left_menu_id" readonly="readonly">
          <template v-for="(item,index) in leftMenuName">
            <el-option :value="index" :label="item" :key="index"></el-option>
          </template>
        </el-select>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input size="small" type="password" v-model="editForm.password" auto-complete="off" style="width: 30%;"></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="password2">
        <el-input size="small" type="password" v-model="editForm.password2" auto-complete="off" style="width: 30%;"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer" style="margin: 40px 0px 0px 380px;">
      <el-button size="small" @click="closeDialog">取消</el-button>
      <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm()">保存</el-button>
    </div>
  </div>
</template>

<script>
  import {
    StaffUpdate,
  } from '../../api/adminMG'
  import {
      getStore
    } from '../../utils/util'
  import Pagination from '../../components/Pagination'
  export default {
    data() {
      return {
        category: [],
        show_sku: 1,
        nshow: true, //switch开启
        fshow: false, //switch关闭
        loading: false, //是显示加载
        editFormVisible: false, //控制编辑页面显示与隐藏
        title: '添加',
        editForm: {
          username:'',
          role_name:'',
          password:'',
          password2:'',
        },
        left_menu_id:0,
        leftMenuName:[],
        // rules表单验证
        rules: {
          password: [{
            required: true,
            message: '请输入密码',
            trigger: 'blur'
          }],
          password2: [{
            required: true,
            message: '请再次确认密码',
            trigger: 'blur'
          }]
        },
        formInline: {
          page: 1,
          limit: 10,
          varLable: '',
          varName: '',
          token: localStorage.getItem('logintoken')
        },
        // 删除部门
        seletedata: {
          ids: '',
          token: localStorage.getItem('logintoken')
        },
        userparm: [], //搜索权限
        listData: [], //用户数据
        // 分页参数
        pageparm: {
          currentPage: 1,
          pageSize: 10,
          total: 10
        }
      }
    },
    // 注册组件
    components: {
      Pagination
    },
    /**
     * 数据发生改变
     */

    /**
     * 创建完毕
     */
    created() {
      this.editForm.staff_id = getStore('staffInfo').staff_id
      this.editForm.username = getStore('staffInfo').username;
      this.editForm.role_name = getStore('staffInfo').role_name;
      this.editForm.role_id = getStore('staffInfo').role_id;
      this.leftMenuName = getStore('leftMenuName');
      // this.getdata(this.formInline);
      // this.getCategory();
    },

    /**
     * 里面的方法只有被调用才会执行
     */
    methods: {
      // 分页插件事件
      callFather(parm) {
        this.formInline.page = parm.currentPage
        this.formInline.limit = parm.pageSize
        this.getdata(this.formInline)
      },
      // 搜索事件
      search() {
        this.getdata(this.formInline)
      },
      submitForm(){
        console.log("获取编辑员工表单", this.editForm)
        this.updateStaff();
      },
      //员工编辑
      updateStaff(){
        StaffUpdate(this.editForm)
          .then(res => {
            this.editFormVisible = false
            this.loading = false
            console.log("员工编辑", res)
            if (res.data.result) {
              this.$message({
                type: 'success',
                message: "员工编辑成功"
              })
              this.editForm.password = ''
              this.editForm.password2 = ''
            } else {
              this.$message({
                type: 'warning',
                message: "员工编辑失败!！"+res.message
              })
            }
          })
          .catch(err => {
            this.editFormVisible = false
            this.loading = false
            this.$message.error('员工编辑失败，请稍后再试！')
          })
      },
      // 关闭编辑、增加弹出框
      closeDialog() {
        this.editFormVisible = false
      }
    }
  }
</script>

<style scoped>
  .user-search {
    margin-top: 20px;
  }

  .userRole {
    width: 100%;
  }
</style>
